package com.hzsk.lisence.controller;
import com.hzsk.lisence.entity.LisenceCorporateEntity;
import com.hzsk.lisence.entity.query.LisenceServiceQuery;
import com.hzsk.lisence.entity.response.IncResponce;
import com.hzsk.lisence.service.CorporateService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@CrossOrigin
@RestController
@RequestMapping("/api/lisence/corporate/")
public class LisenceCorporateController {


    @Resource
    private CorporateService corporateService;


    @PostMapping("createcorporate")
    @ApiOperation(value = "创建公司名称")
    public IncResponce createCorporate(@RequestBody LisenceCorporateEntity lisenceCorporateEntity){
        IncResponce incResponce = new IncResponce();
        try {
          synchronized (this){
              corporateService.createCorporate(lisenceCorporateEntity,lisenceCorporateEntity.getOperatorUserId(),incResponce);
          }
        } catch (Exception e) {
            incResponce.setCode(-1);
            incResponce.setErrorMessage(e.toString());
            e.printStackTrace();
        }
        return incResponce;
    }


    @PostMapping("getallcorporateinfo")
    @ApiOperation(value = "查看公司信息")
    public IncResponce getAllCorporateInfo(@RequestBody LisenceServiceQuery lisenceServiceQuery){
        IncResponce incResponce = new IncResponce();
        try {
            corporateService.getAllCorporateInfo(lisenceServiceQuery,incResponce);
        } catch (Exception e) {
            incResponce.setCode(-1);
            incResponce.setErrorMessage(e.toString());
            e.printStackTrace();
        }
        return incResponce;
    }



    @GetMapping("getallcorporate")
    @ApiOperation(value = "查看公司信息不分页所有")
    public IncResponce getAllCorporate(){
        IncResponce incResponce = new IncResponce();
        try {
            corporateService.getAllCorporate(incResponce);
        } catch (Exception e) {
            incResponce.setCode(-1);
            incResponce.setErrorMessage(e.toString());
            e.printStackTrace();
        }
        return incResponce;
    }



    @PutMapping("updatecorporateinfo")
    @ApiOperation(value = "修改公司信息")
    public IncResponce updateCorporateInfo(@RequestBody LisenceCorporateEntity lisenceCorporateEntity){
        IncResponce incResponce = new IncResponce();
        try {
            corporateService.updateCorporateInfo(lisenceCorporateEntity,lisenceCorporateEntity.getOperatorUserId(),incResponce);
        } catch (Exception e) {
            incResponce.setCode(-1);
            incResponce.setErrorMessage(e.toString());
            e.printStackTrace();
        }
        return incResponce;
    }


    @DeleteMapping("delcorporateinfo")
    @ApiOperation(value = "删除公司信息")
    public IncResponce delCorporateInfo(@RequestParam("id")Integer id ,@RequestParam("operatorUserId")Integer operatorUserId ){
        IncResponce incResponce = new IncResponce();
        try {
            corporateService.delCorporateInfo(id,operatorUserId,incResponce);
        } catch (Exception e) {
            incResponce.setCode(-1);
            incResponce.setErrorMessage(e.toString());
            e.printStackTrace();
        }
        return incResponce;
    }



}
